import sys
import os
from datetime import datetime

if __name__ == '__main__':
    source_dir = 'C:/Users/86173/PycharmProjects/pythonProject/data'
    dest_dir = 'C:/Users/86173/PycharmProjects/pythonProject/'
    today = datetime.today().strftime('%Y%m%d')
    basename = os.path.basename(source_dir)
    dest_dir = os.path.join(dest_dir, '%s_%s' % (basename, today))

    print("开始备份...", source_dir, dest_dir)
    if not os.path.isdir(dest_dir):
        os.mkdir(dest_dir)
    for file in os.listdir(source_dir):
        if os.path.isdir(file):
            continue
        filename = os.path.basename(file)
        backup_file = os.path.join(dest_dir, filename)
        dest_file = os.path.join(source_dir, filename)
        with open(dest_file, 'rb') as fr, open(backup_file, 'wb') as fw:
            fw.write(fr.read())
    print("备份成功！!")